﻿using UnityEngine;
using System.Collections;

public class NoteTrait : MonoBehaviour {

    public TraitData m_traitData;
    public bool m_bTrait;
    public int m_iIndx;

    bool m_bInformOn;
	// Use this for initialization
	void Start () {
        transform.localScale = new Vector3(0.1f, 0.1f);

        switch (m_iIndx)
        {
            case 0:
                transform.localPosition = new Vector3(-24.4f, -5.7f);
                break;
            case 1:
                transform.localPosition = new Vector3(-38.05f, -17.15f);
                break;
            case 2:
                transform.localPosition = new Vector3(-24.4f, -17.15f);
                break;
            case 3:
                transform.localPosition = new Vector3(-10.7f, -17.15f);
                break;
        }

        if (m_bTrait)
        {
            GetComponent<UISprite>().spriteName = m_traitData.m_strSpriteName;
        }
        else
        {
            GetComponent<UISprite>().spriteName = transform.parent.parent.parent.FindChild("UnitNoteClass").GetComponent<UISprite>().spriteName;
        }
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnHover(bool isOver)
    {
        if (isOver)
        {
            if (!m_bInformOn)
            {
                ResourceMgr.GetInstance().CreateInformBox(m_traitData.m_strName, m_traitData.m_strDesc);
                m_bInformOn = true;
            }
        }
        if (!isOver && m_bInformOn)
        {
            m_bInformOn = false;
            for (int i = 0; i < GameObject.Find("InformBoxUI").transform.childCount; ++i)
            {
                Destroy(GameObject.Find("InformBoxUI").transform.GetChild(i).gameObject);
            }
        }
    }
}
